<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="opAdd">新增调拨</el-button>
			</div>
			<div class="right-panel">
				<el-button :icon="Search"   type="primary" @click="opBindData">查询</el-button>
				<el-button :icon="Search" type="info" plain @click="resetSearch">重置</el-button>
				<el-button text type="primary" @click="showCondition = !showCondition">
					<span v-if="!showCondition">展开</span>
					<span v-else>收起</span>
					<vab-icon class="vab-dropdown" :class="{ 'vab-dropdown-active': fold }" icon="arrow-up-s-line" />
				</el-button>
			</div>
		</el-header>
		<el-foot v-show="showCondition">
			<vab-query-form-top-panel>
				<el-form inline label-width="49px" :model="queryForm" style="margin-top: 5px">
					<el-form-item label="调拨时间" label-width="100px">
						<el-date-picker style="width: 300px" v-model="queryList.AllocateDate" type="datetimerange"
							value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss" range-separator="-"
							unlink-panels="true" start-placeholder="开始时间" end-placeholder="结束时间" :default-time="defaultTime"/>
					</el-form-item>
					<el-form-item label="调出仓库" label-width="100px">
						<sc-warehouse-select ref="orgselect" :props="warehouseProps" :selectKeyValue="'warehouseId'"
							v-model="queryList.outwarehouses" @fatherMethod="outwarehouseSelectProcess"
							:multiple="false"></sc-warehouse-select>
					</el-form-item>
					<el-form-item label="调出入库" label-width="100px">
						<sc-warehouse-select ref="orgselect" :props="warehouseProps" :selectKeyValue="'warehouseId'"
							v-model="queryList.inwarehouses" @fatherMethod="inwarehouseSelectProcess"
							:multiple="false"></sc-warehouse-select>
					</el-form-item>
					<el-form-item label="单据金额" label-width="100px">
						<el-input placeholder="---请输入最小单据金额---" v-model="queryList.MinTotalAmount"
							style="width: 145px" />
						<span style="width: 10px;">-</span>
						<el-input placeholder="---请输入最大单据金额---" v-model="queryList.MaxTotalAmount"
							style="width: 145px" />
					</el-form-item>
					<el-form-item label="调拨单号" label-width="100px">
						<el-input placeholder="---请输入调拨单号---" v-model="queryList.AllocateOrderCode"
							style="width: 300px" />
					</el-form-item>
					<el-form-item label="物料名称" label-width="100px">
						<el-input placeholder="---请输入物料名称---" v-model="queryList.MaterialName" style="width: 300px" />
					</el-form-item>
					<el-form-item label="物料编码" label-width="100px">
						<el-input placeholder="---请输入物料编码---" v-model="queryList.MaterialCode" style="width: 300px" />
					</el-form-item>
				</el-form>
			</vab-query-form-top-panel>
		</el-foot>
		<el-main class="nopadding">
			<scTable ref="mytable" :queryType="'allocate-order/pages'" :data="listData" :queryList="queryList"
				:column="columnList" :orderList="OrderList" :sort-orders="['ascending', 'descending']"
				@selection-change="selectionChange" :row-class-name="setRowClass" row-key="AllocateOrderId"
				key="AllocateOrderId" show-summary remoteSummary>
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="序号" type="index" width="80" align="center"></el-table-column>
				<el-table-column label="调拨时间" prop="allocateDate" width="250">
					<template #default="scope">
						{{ scope.row.allocateDate? scope.row.allocateDate.slice(0, 10):'' }}
					</template>
				</el-table-column>
				<el-table-column label="调拨单号" prop="allocateOrderCode" width="250">
					<template #default="scope"> <span class="el-span-text"
							@click="opPrintview(scope.row, scope.$index)">{{scope.row.allocateOrderCode}}</span></template>
				</el-table-column>
				<el-table-column label="调出仓库" prop="outWarehouseName" width="250"></el-table-column>
				<!-- <el-table-column label="业务员" prop="salesman" width="250"></el-table-column> -->
				<el-table-column label="调入仓库" prop="inWarehouseName" width="150"></el-table-column>
				<!-- <el-table-column label="签收人" prop="signUser" width="250"></el-table-column> -->
				<el-table-column label="单据金额" prop="totalAmount" width="150"></el-table-column>
				<el-table-column label="物料详情" width="150">
					<template #default="scope"> <span class="el-span-text"
							@click="opPrintview(scope.row, scope.$index)">查看详情</span></template>
				</el-table-column>
				<el-table-column label="备注" prop="remarks" width="250">

				</el-table-column>
				<el-table-column label="操作" fixed="right" align="center" width="240">
					<template #default="scope">
						<el-button-group>
							<el-button v-if="scope.row.reviewedStatus!=1" text type="primary" size="small"
								@click="opEdit(scope.row, scope.$index)">编辑</el-button>
							<el-button v-if="scope.row.reviewedStatus!=1" text type="primary" size="small"
								@click="opDel(scope.row, scope.$index)">删除</el-button>
							<el-button text type="primary" size="small"
								@click="opCopy(scope.row, scope.$index)">复制</el-button>
							<el-button v-if="scope.row.reviewedStatus==0" text type="primary" size="small"
								@click="opReviewed(scope.row, scope.$index)">审核</el-button>
								<el-button v-if="scope.row.reviewedStatus==1" text type="primary" size="small"
								@click="antiAudit(scope.row, scope.$index)">反审核</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>

		</el-main>
	</el-container>
	<allocate-dialog ref="allocateDialog" @fatherMethod="opBindData"></allocate-dialog>
	<reviewed-dialog ref="reviewedDialog" @fatherMethod="opBindData"></reviewed-dialog>
</template>

<script>
	import allocateDialog from './allocate.vue'
	import reviewedDialog from './reviewed.vue'
	export default {
		name:"allocateorder",
		data() {
			return {
				queryList: {},
				showCondition: false,
				warehouseProps: {
					label: "warehouseName",
					value: "warehouseId",
				},
				defaultTime:[
					new Date(2000, 1, 1, 0, 0, 0),
					new Date(2000, 2, 1, 23, 59, 59),
				]
			}
		},
		components: {
			allocateDialog,
			reviewedDialog
		},
		methods: {
			opAdd() {
				this.$refs.allocateDialog.open();
			},
			async opBindData() {
				this.$refs.mytable.clearSort();
				this.$refs.mytable.getData();
			},
			resetSearch() {
				this.queryList = {}
			},
			//仓库
			async outwarehouseSelectProcess(rowData) {
				this.queryList.OutWarehouseId = this.queryList.outwarehouses.warehouseId
			},
			async inwarehouseSelectProcess(rowData) {
				this.queryList.InWarehouseId = this.queryList.inwarehouses.warehouseId
			},
			async opPrintview(row) {
				this.$refs.allocateDialog.open('Show');
				this.$refs.allocateDialog.setData(row)
			},
			async opCopy(row) {
				this.$refs.allocateDialog.open();
				this.$refs.allocateDialog.copy(row)
			},
			async opEdit(row) {
				this.$refs.allocateDialog.open('Edit');
				this.$refs.allocateDialog.setData(row);
			},
			async opReviewed(row) {
				this.$refs.reviewedDialog.open();
				this.$refs.reviewedDialog.setData(row);
			},
			//反审核
			async antiAudit(row){
				try {
					var returnValue = await this.$API.auth.PostProcessApi.post(
						"allocate-order/anti-audit", {
							allocateOrderIds: [row.allocateOrderId]
						}
					);
					if (returnValue.status == 200) {
						this.$message.success("操作成功");
						this.$refs.mytable.getData();
					} else {
						this.$message.error("操作失败:" + returnValue.msg);
					}
				} catch (error) {
					this.loading = false;
					return false;
				}
			},
			async opDel(row) {
				this.$confirm("确定要删除吗？", "提示", {
						confirmButtonText: "确定",
						cancelButtonText: "取消",
						type: "warning",
					})
					.then(async () => {
						try {
							var returnValue = await this.$API.auth.PostProcessApi.post(
								"allocate-order/delAllocateOrder", row
							);
							if (returnValue.status == 200) {
								this.$message.success("删除成功");
								this.opBindData();
							} else {
								this.$message.error("操作失败:" + returnValue.msg);
							}
						} catch (error) {
							this.$message.error("操作失败:" + error);
							return false;
						}
					})
					.catch(() => {
						// 用户点击了取消按钮，不执行关闭
					});
			}
		},
		async mounted() {
			var allocateOrderCode=this.$route.query.allocateOrderCode;
			if(allocateOrderCode){
			    this.queryList.AllocateOrderCode=allocateOrderCode;
			}
			await this.opBindData();
		},
	}
</script>

<style>
</style>
